package com.globalwave.common.appframe
{
	import com.globalwave.common.event.KeyHandler;
	import com.globalwave.pos.frontpage.TopTitle;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	
	import mx.containers.Canvas;
	import mx.containers.TitleWindow;
	import mx.controls.Alert;
	import mx.core.FlexGlobals;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;
	
	import spark.components.BorderContainer;
	
	public class PopupModuleBox extends Canvas
	{
		private var moduleLoader:ModuleLoader ;
		private var url:String ;
		private var keyEventActor:Object = new Object();
		
		public function PopupModuleBox(moduleUrl:String)
		{
			this.url = moduleUrl ;
			
			var app:DisplayObject = DisplayObject(FlexGlobals.topLevelApplication) ;
			this.width = app.width ;
			this.height = app.height ;
			this.setStyle("backgroundColor",0xffffff) ;
			
			this.moduleLoader = new ModuleLoader(this) ; 
			this.addEventListener("initialize", thisOnInit) ;

			PopUpManager.addPopUp(this, app, true);
			//this.stage.addEventListener(KeyboardEvent.KEY_UP, keyboardOnKeyUp) ;
		}
		
		public function keyboardOnKeyUp(event:KeyboardEvent):void {
			if(event.keyCode == Keyboard.ESCAPE) {
			    esc() ;
			}
		}
		public function esc():void {			
			
			mx.controls.Alert.show(
				"是否退出当前功能？" , 
				"关闭确认", 
				Alert.YES|Alert.NO, 
				null,
				escOnConfirm); 
		}
		
		private function escOnConfirm(event:CloseEvent):void {	
			if (event.detail==Alert.YES) {
				PopUpManager.removePopUp(this);
				KeyHandler.getInstance().popActor();
			}
		}
		
		protected function thisOnInit(e:Event):void {	
			moduleLoader.load(url);
			
			KeyHandler.getInstance().pushActor(keyEventActor);
			keyEventActor[Keyboard.ESCAPE] = esc ;
		}
	}
}